package filter.session;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 取session中的值(Session3)
 */
public class Session4 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决编码显示问题
        req.setCharacterEncoding("gbk");
        resp.setCharacterEncoding("gbk");
        //指定显示
        resp.setContentType("text/html;charset=gbk");
        //得到session
        HttpSession session = req.getSession();

        //取session中的值
        Person name = (Person) session.getAttribute("name");
        resp.getWriter().write(name.toString());
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
